<!DOCTYPE html>
<html lang="zh-CN">
  <!--复用页面tags-list.html-->
  <!--1.差异部分为getTagList方法|2.  <div class="right">-->
  <!--  测试参数 id="3" -->
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"
    />

    <meta name="description" content="描述" />
    <meta name="keywords" content="关键词" />
    <link rel="icon" href="" />
    <link rel="shortcut icon" href="" />
    <link rel="stylesheet" href="/web/lib/search-history/index.css" />
    <title>电梯采购网</title>
    <link rel="stylesheet" href="/web/public/css/public.css">
    <link rel="stylesheet" href="/web/public/css/header.css">
    <link rel="stylesheet" href="/web/public/css/footer.css">
    <link rel="stylesheet" href="/web/public/css/search_list.css">
    <link rel="stylesheet" href="/web/public/css/right.css">

    <script src="/web/lib/jquery-1.12.4.min.js"></script>
    <script src="/web/public/public.js"></script>
    <script src="/web/lib/jquery.pagination.js"></script>
  </head>
  <body>
    <div class="container">
      <!--这里引入header-->
      <include file="/web/html/header/header.htm" page-type="1"></include>
      <div id="main">
        <div class="top">
          <div class="search-warp">
            <div class="search-box">
              <div class="input-wrap">
                <i class="icon-search"></i>
                <input class="search-input" type="text" />
                <!-- 历史记录入口 -->
                <div class="history-list"></div>
              </div>
              <div class="search-btn-left" id="id_ssbt">搜索标题</div>
              <div class="search-btn-center" id="id_ssqw">搜索全文</div>
            </div>
            <ul class="list-title">
              <li class="active"><a href="javascript:">全部</a></li>
              <li><a href="javascript:">法规</a></li>
              <li><a href="javascript:">案例</a></li>
              <li><a href="javascript:">资讯</a></li>
              <li><a href="javascript:">专题</a></li>
              <div class="search-btn-toright">
                <a id="id_ssbx" href="javascript:">标讯</a>
              </div>
              <!--20210204-->
              <div class="search-right-text-box" id="id_search-result-text-box">
                <span class="search-right-text" id="id_search-result-text"
                  >含“汽车汽【引号这里最多显示24个字超出用...代替】汽车汽车汽...”的搜索标题结果为32323232条</span
                >
              </div>
            </ul>
          </div>
          <ul class="list-order-btn">
            <li class="active">
              <i class="iconfont icon-biezhen"></i
              ><span href="javascript:">相关性</span>
            </li>
            <li>
              <i class="iconfont icon-shijian1"></i
              ><span href="javascript:">发布时间</span>
            </li>
          </ul>
        </div>
        <div class="left">
          <ul class="content-list">
            <!-- <li>
                     <div class="left">
                         <img src="/web/img/list-img-1.png" alt="图片">
                     </div>
                     <div class="right">
                         <div class="title"><a href="javascript:">标题最多显示20个字符,字号20像素#333333</a></div>
                         <p class="intro">
                             内容介绍最多显示55各自,字号14像素#7f7f7f企业都在苦苦挣扎，长
                             城汽车每月销量却在逆势增长增长增长增长对对对。
                         </p>
                         <div class="info">
                             <i class="iconfont icon-renwu-touxiang"></i><span>刘轩赫/整理</span>
                             <i class="iconfont icon-shijian"></i><span>2020-09-08</span>

                             <a href="javascript:" class="tag">集采机构</a>
                             <a href="javascript:" class="tag">采购人</a>
                         </div>
                     </div>
                 </li>-->
          </ul>
          <div class="list-pagination"></div>
        </div>
        <div class="right">
          <!--            视频课堂-->
          <include file="/web/html/fragment/video-classroom.htm"></include
          ><!-- 20201111-->
          <!--          亚利聊政采 -->
          <include file="/web/html/fragment/home-inc/yllzc.htm"></include
          ><!-- 20201111-->
          <!--           热点专题 -->
          <include file="/web/html/fragment/home-inc/hot-topic.htm"></include
          ><!-- 20201111-->
          <!--            热搜榜-->
          <include file="/web/html/fragment/index-hot-search.htm"></include
          ><!-- 20201111-->
          <!-- 广告位(马老师不确定) -->
          <include file="/web/html/fragment/right-ad.htm"></include
          ><!-- 20201111-->
        </div>
      </div>
      <include file="/web/html/footer/footer.htm"></include>
    </div>
    <script>
      var $aListTileLi = $("ul.list-title>li"); //分类tab标签
      var $aListOrderLi = $("ul.list-order-btn>li"); //分类排序按钮
      var bufArticleType = 0; //当前选中分类tab标签/法规0/案例1/资讯2/专题3
      var bufSort = 0; //当前选中分类排序按钮/相关性0/发布时间1
      var bufSearchType = 0; //搜索标题0/搜索全文1
      var tagId = utils.getQueryVariable("id");
      var inputSearch = utils.getQueryVariable("inputSearch");
      var searchType = utils.getQueryVariable("searchType");
      $(function () {
        console.log(searchType);
        if (searchType == null) {
          bufArticleType = 0;
        } else {
          bufArticleType = searchType;
          $aListTileLi.removeClass("active");
          $aListTileLi.eq(bufArticleType).addClass("active");
        }
        if (inputSearch) {
          $(".search-box .input-wrap>input").val(decodeURI(inputSearch));
        }
        $.ajax({
          url: ports.getTagListTdk,
          data: {
            keyword: tagId,
          },
          success: function (res) {
            console.log("获取标签列表tdk", res);
            $("title").text(
              res.data.channelTitle + "-政府采购信息网" || "政府采购信息网"
            );
            $("meta[name='keywords']").prop(
              "content",
              res.data.channelKeyword || ""
            );
            $("meta[name='description']").prop(
              "content",
              res.data.channelDescriptions || ""
            );
          },
        });
        //分类tab标签
        $aListTileLi.click(function () {
          bufArticleType = $(this).index();
          $aListTileLi.removeClass("active");
          $(this).addClass("active");
          getTagList(
            getsearchType(),
            getsort(),
            getarticleType(),
            getqueryText(),
            1,
            true
          );
        });
        //分类排序按钮
        $aListOrderLi.click(function () {
          bufSort = $(this).index();
          $aListOrderLi.removeClass("active");
          $(this).addClass("active");
          getTagList(
            getsearchType(),
            getsort(),
            getarticleType(),
            getqueryText(),
            1,
            true
          );
        });
        //搜索标题type点击监听
        $("#id_ssbt").click(function () {
          console.log("搜索标题type点击监听");

          // console.log("$searchValue=" + $searchValue);
          // $('#id_search-result-text-box').hide();
          bufSearchType = 0;
          getTagList(
            getsearchType(),
            getsort(),
            getarticleType(),
            getqueryText(),
            1,
            true
          );
        });
        //搜索全文type点击监听
        $("#id_ssqw").click(function () {
          console.log("搜索全文type点击监听");

          bufSearchType = 1;
          getTagList(
            getsearchType(),
            getsort(),
            getarticleType(),
            getqueryText(),
            1,
            true
          );
        });
        //搜索外链易找标
        $("#id_ssbx").click(function () {
          //	跳转
          // $(location).attr('href', 'https://yzb.caigou2003.com/index.html#/frontHome/searchResult?searchPageType=1&inputSearch='+getqueryText()+'&method=1');
          window.open(
            "https://yzb.caigou2003.com/index.html#/frontHome/searchResult?searchPageType=1&inputSearch=" +
              getqueryText() +
              "&method=1"
          );
        });
        getTagList(
          getsearchType(),
          getsort(),
          getarticleType(),
          getqueryText(),
          1,
          true
        );
        onload();
      });
      //列表
      /* searchType  1搜索标题 2搜索全文
         sort   1相似度排序 2时间倒序  默认1
         articleType  0 全部 1 资讯 2法规 3案例 5专题
         queryText  关键词
         pageNum 页码
         pageSize 分页*/
      function getTagList(
        searchType,
        sort,
        articleType,
        queryText,
        pageNum,
        resetPage
      ) {
        var pageSize = 10;
        $.ajax({
          url: ports.front_article_es_list,
          data: {
            searchType: searchType,
            sort: sort,
            articleType: articleType,
            queryText: queryText,
            pageNum: pageNum,
            pageSize,
            pageSize,
          },
          success: function (res) {
            console.log("获取标签列表11", res);
            var tagListHtml = "";
            var tagList = res.data.list;
            if (tagList && tagList.length) {
              //20201216
              tagList.forEach(function (item) {
                var keywordsListHtml = "";
                item.articleKeywords.forEach(function (item1) {
                  keywordsListHtml +=
                    "<a href=" +
                    "/web/html/list/tags-list.html?id=" +
                    item1.value +
                    ' class="tag">' +
                    item1.label +
                    "</a>";
                });
                tagListHtml +=
                  "<li>\n" +
                  (item.articleImage
                    ? '<div class="left">' +
                      '<a target="_blank" href=' +
                      item.articleUrl +
                      ">" +
                      "<img src=" +
                      item.articleImage +
                      " alt=" +
                      item.articleTitle +
                      "></a></div>"
                    : "") + //20210118
                  '                    <div class="right">\n' +
                  '                        <div class="title"><a target="_blank" href=' +
                  item.articleUrl +
                  ">" +
                  item.articleTitle +
                  "</a></div>\n" +
                  "                        <p>\n" +
                  '<a target="_blank" href=' +
                  item.articleUrl +
                  ">" +
                  item.articleInfo +
                  "</a>" + //20210118
                  "                        </p>\n" +
                  '                        <div class="info">\n' +
                  (item.articleReleaseTime
                    ? '                            <i class="iconfont icon-shijian"></i><span>' +
                      item.articleReleaseTime.substr(0, 10) +
                      "</span>\n"
                    : "") + //20210118
                  "\n" +
                  keywordsListHtml +
                  "                        </div>\n" +
                  "                    </div>\n" +
                  "                </li>";
              });
              $(".list-pagination").css("visibility", "visible"); //显示div20201216
            } else {
              //20201216
              tagListHtml = '<li class="no-data">暂无数据</li>'; //20201216
              // $('.list-pagination').remove();20201216
              $(".list-pagination").css("visibility", "hidden"); //隐藏div//20201216
            } //20201216
            $("ul.content-list").html(tagListHtml);
            //结果显示文案设置
            setResultText(res.data.total);
            if (resetPage) {
              $(".list-pagination").pagination({
                prevContent: "< 上一页",
                nextContent: "下一页 >",
                totalData: res.data.total,
                showData: pageSize,
                coping: true,
                callback: function (api) {
                  console.log(api.getCurrent());
                  var current = api.getCurrent();
                  document.body.scrollTop = 0;
                  document.documentElement.scrollTop = 0;
                  // getTagList(current, false);
                  getTagList(
                    searchType,
                    sort,
                    articleType,
                    queryText,
                    current,
                    false
                  );
                },
              });
            }
          },
        });
        recordHistory(queryText);
      }

      //结果显示文案设置
      // 含“汽车汽【引号这里最多显示24个字超出用...代替】汽车汽车汽...”的搜索标题结果为32323232条
      function setResultText(total) {
        let bufStr = "含“";
        bufStr +=
          getqueryText().length > 24
            ? getqueryText().substr(0, 24) + "..."
            : getqueryText();
        bufStr += "”的";
        bufStr += getsearchText();
        bufStr += "结果为";
        bufStr += total;
        bufStr += "条";
        // 共找到 10802746 条内容
        $("#id_search-result-text")[0].innerHTML = bufStr;
        $("#id_search-result-text-box").show();
      }

      /* searchType  1搜索标题 2搜索全文
               sort   1相似度排序 2时间倒序  默认1
               articleType  0 全部 1 资讯 2法规 3案例 5专题
               queryText  关键词
               pageNum 页码
               pageSize 分页*/
      function getsearchType() {
        if (bufSearchType == 0) {
          return 1;
        } else if (bufSearchType == 1) {
          return 2;
        }
      }

      function getsearchText() {
        // 搜索标题0/搜索全文1
        if (bufSearchType == 0) {
          return "搜索标题";
        } else if (bufSearchType == 1) {
          return "搜索全文";
        }
      }

      function getsort() {
        if (bufSort == 0) {
          return 1;
        } else if (bufSort == 1) {
          return 2;
        }
      }

      // bufArticleType = 0;//当前选中分类tab标签 /全部0/法规1/案例2/资讯3/专题4
      function getarticleType() {
        if (bufArticleType == 0) {
          return 0;
        } else if (bufArticleType == 1) {
          return 2;
        } else if (bufArticleType == 2) {
          return 3;
        } else if (bufArticleType == 3) {
          return 1;
        } else if (bufArticleType == 4) {
          return 5;
        }
      }

      function getqueryText() {
        return $(".search-box .input-wrap>input").val();
      }
      function onload() {
        let input = $("input.search-input");
        input.focus(() => {
          // 获取历史记录
          let history = JSON.parse(localStorage.getItem("history") || "[]");
          let f = $(".history-list");
          // 先清空item
          f.find(".history-item").remove();
          // 再从缓存中循环添加item
          history.forEach((item) => {
            f.append($("<div class='history-item item'>" + item + "</div>"));
          });
          // 如果有历史记录，就加入删除功能
          history.length &&
            f.append($("<div class='history-item del'>删除记录</div>"));
          $(".history-list").css("display", "block");
          // 监听删除点击事件
          $("div.history-item.del").click(() => {
            localStorage.removeItem("history");
          });
          // 监听历史记录点击事件, 注意this指向
          $("div.history-item.item").click(function () {
            input.val($(this).text());
            bufSearchType = 0;
            getTagList(
              getsearchType(),
              getsort(),
              getarticleType(),
              getqueryText(),
              1,
              true
            );
          });
        });
        input.blur(() => {
          setTimeout(() => {
            $(".history-list").css("display", "none");
          }, 200);
        });
      }
      /**
       * 搜索历史记录
       * @param {String} queryText 关键词
       */
      function recordHistory(queryText) {
        let history = JSON.parse(localStorage.getItem("history") || "[]");
        if (!!queryText) {
          let i = history.indexOf(queryText);
          i !== -1 && history.splice(i, 1);
          history.unshift(queryText);
          history.length >= 6 && (history.length = 5);
        }
        localStorage.setItem("history", JSON.stringify(history));
      }
    </script>
  </body>
</html>
